package com.tds.springbootdemo2;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;

import java.io.File;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Copyright (C) 2014-2023 天津紫藤科技有限公司. Co. Ltd. All Rights Reserved.
 *
 * @author tongdashuai
 * @version 1.0
 * @description
 * @module
 * @date 2024/10/18 15:03
 */
public class MyTest2 {

    public static void main(String[] args) {
//        System.out.println("原始sql：" + "a=??".replaceAll("\\?", "{}"));
//        System.out.println(Integer.parseInt("x0010"));;

        JSONArray jsonArray = JSONUtil.readJSONArray(new File("C:\\Users\\zity\\Desktop\\tmp\\通用食堂补录失败json串.txt"), Charset.defaultCharset());
        int num = 0;
        List<Map> list = new ArrayList<>();
        for (Object o : jsonArray) {
            JSONObject jo = (JSONObject) o;
            String name = jo.getStr("name");
            String phone = jo.getStr("phone");
            String failReason = jo.getStr("failReason");
            Map map = new HashMap<>();
            map.put("name", name);
            map.put("phone", phone);
            map.put("failReason", failReason);
            if (StrUtil.isBlank(failReason)) {
                num++;
                continue;
            }
            list.add(map);
            System.out.println(map);
        }
        System.out.println("失败数：" + num);
        System.out.println("成功数:" + (list.size() - num));
        ExcelWriter writer = ExcelUtil.getBigWriter("C:\\Users\\zity\\Desktop\\tmp\\补录失败原因.xlsx")
                .addHeaderAlias("name", "名字")
                .addHeaderAlias("phone", "手机号")
                .addHeaderAlias("failReason", "失败原因")
                .setColumnWidth(1, 20)
                .setColumnWidth(2, 30)
                .write(list);
        writer.close();;
    }
}
